<?php 
session_start();
ob_start();
?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("userinfo.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("phpmkrfn.php") ?>
<?php include ('../classes/class.mysql.admin.php'); ?>
<?php
if (@$_POST["email"] <> "") {
	$bValidEmail = false;

	// Setup variables
	$sEmail = @$_POST["email"];
	$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);
	$sEmail = (!get_magic_quotes_gpc()) ? addslashes($sEmail) : $sEmail;
	$sFilter = "`email` = '" . AdjustSql($sEmail) . "'";
	$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
	$rs = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
	if (phpmkr_num_rows($rs) > 0) {
		$row = phpmkr_fetch_array($rs);
		$sPassword=substr(generateHash(date("Y-m-d H:i:s")),-8,8);
		$cn = new mysql_class();
		$cn->execute("UPDATE `user` SET `password`='".generateHash($sPassword)."' WHERE `email`='".$sEmail."'");
		$bValidEmail = true;
		$bValidEmail = true;
	}
	phpmkr_free_result($rs);
	phpmkr_db_close($conn);
	if ($bValidEmail) {

		// Load email content
		LoadEmail("forgetpwd.txt");
		$sEmailFrom = str_replace("<!--\$From-->", "webmaster@smart-karaoke.com",$sEmailFrom); // Replace sender
		$sEmailTo = str_replace("<!--\$To-->", $sEmail,$sEmailTo); // Replace recipient
		$sEmailContent = str_replace("<!--\$Password-->", $sPassword,$sEmailContent); // Replace password

		// Send email
		Send_Email($sEmailFrom, $sEmailTo, $sEmailCc, $sEmailBcc, $sEmailSubject, $sEmailContent, $sEmailFormat);
		$_SESSION[ewSessionMessage] = "Password sent to your email";
		ob_end_clean();
		header("Location: login.php");
		exit();
	}
} else {
	$bValidEmail = true;
}
?>
<?php include ("header.php") ?>
<script type="text/javascript" src="ewp.js"></script>
<script type="text/javascript">
<!-- start JavaScript
	function  EW_checkMyForm(EW_this) {
	if  (!EW_hasValue(EW_this.email, "TEXT" )) {
	            if  (!EW_onError(EW_this, EW_this.email, "TEXT", "Please enter valid Email Address!"))
	                return false;
	        }
	if  (!EW_checkemail(EW_this.email.value)) {
	            if  (!EW_onError(EW_this, EW_this.email, "TEXT", "Please enter valid Email Address!"))
	                return false;
	        }
	return true;
	}

// end JavaScript -->
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="admin_td_title">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td class="admin_title">Request Password Page</td>
		   </tr>
		 </table>
 	</td>
  </tr>
</table>
<br><br>
<a href="login.php">Back to Login Page</a>
</span></p>
<?php if (!$bValidEmail) { ?>
<p><span class="phpmaker" style="color: Red;">Invalid Email</span></p>
<?php } ?>
<form action="forgetpwd.php" method="post" onSubmit="return EW_checkMyForm(this);">
<table border="0" cellspacing="0" cellpadding="4">
	<tr>
		<td><span class="phpmaker">User Email</span></td>
		<td><span class="phpmaker"><input type="text" name="email" value="<?php echo @$sEmail; ?>" size="60" maxlength="255"></span></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><span class="phpmaker"><input type="submit" name="submit" value="Send Password"></span></td>
	</tr>
</table>
</form>
<br>
<?php include ("footer.php") ?>
